import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import legacy from '@vitejs/plugin-legacy'

import Components from 'unplugin-vue-components/vite'
import { AntDesignVueResolver } from 'unplugin-vue-components/resolvers'

// https://vite.dev/config/
export default defineConfig(() => {
  return {
    base: './',
    define: {
      APP_MOCK_ENABLE: JSON.stringify(process.argv.includes('--mock')),
    },
    plugins: [
      vue(),
      vueJsx(),
      legacy(),
      Components({
        resolvers: [
          AntDesignVueResolver({
            importStyle: false, // css in js
          }),
        ],
      }),
    ],
    resolve: {
      alias: {
        '@': fileURLToPath(new URL('./src', import.meta.url)),
      },
    },
    server: {
      proxy: {
        '/api': {
          // target: 'http://192.168.1.222:8888',
          // target: 'http://139.224.43.89:8888',
          // target: 'http://127.0.0.1:8000',
          target: 'http://139.196.179.195:12395',
          // target: 'http://192.168.1.13:12395',
          changeOrigin: true,
          rewrite: path => {
            return path.replace(/^\/api/, '')
          },
        },
      },
    },
  }
})
